package com.main.util;

import org.springframework.stereotype.Component;

/**
 * 验证码生成工具
 *
 * @author zhouRuoYu
 * @date 2022/10/02
 */
@Component
public class CaptchaUtils {


    private final String[] patch = {"000000", "00000", "0000", "000", "00", "0", ""};

    public String getCode(String tele) {
        int hash = tele.hashCode();
        int encryption = 20206666;
        long result = hash ^ encryption;
        long nowTime = System.currentTimeMillis();
        result = result ^ nowTime;
        long code = result % 1000000;
        code = code < 0 ? -code : code;
        String codeStr = code + "";
        int len = codeStr.length();
        return patch[len] + codeStr;
    }


}
